package com.htu.courseService.picture.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.htu.courseService.common.enums.RedisCachePrefix;
import com.htu.courseService.common.util.MinioUtil;
import com.htu.courseService.picture.dao.PictureMapper;
import com.htu.courseService.picture.entity.Picture;
import com.htu.courseService.picture.service.PictureService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class PictureServiceImpl implements RedisCachePrefix, PictureService {
    private final PictureMapper pictureMapper;
    private final MinioUtil minioUtil;
    @Override
    public List<Picture> getPictureList() {
        LambdaQueryWrapper<Picture> wrapper = new LambdaQueryWrapper<>();
        wrapper.isNotNull(Picture::getId);
        List<Picture> pictureList = pictureMapper.selectList(wrapper);
        return pictureList;
    }

    @Override
    public void uploadFile(String fileUrl) {
        Picture picture = new Picture();
        picture.setFileUrl(fileUrl);
        picture.setCreatedAt(new Date());
        pictureMapper.insert(picture);
    }

    @Override
    public void deleteFile(Integer id) {
        pictureMapper.deleteById(id);
    }
}
